package com.cucn.ingmall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池的配置
 *
 * @author KouChaoJie
 * @since: 2022/1/6 15:07
 */
@Configuration
public class MyThreadConfig {
    /**
     * 线程池的配置
     *
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties poolConfigProperties) {
        return new ThreadPoolExecutor(
                poolConfigProperties.getCorePoolSize(),
                poolConfigProperties.getMaxSize(),
                poolConfigProperties.getKeepAliveTimes(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
